//
//  SEGBaseTableViewCell.m
//  SEGBasicBussiness
//
//  Created by Clavis on 2018/10/29.
//  Copyright © 2018 刘山. All rights reserved.
//

#import "SEGBaseTableViewCell.h"

#if __has_include(<Commom/SEGColorManager.h>)
#import <Commom/SEGColorManager.h>
#else
#import "SEGColorManager.h"
#endif

@interface SEGBaseTableViewCell ()

@property (nonatomic, strong) UIView *tempBackgroundView;

@end

@implementation SEGBaseTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.tempBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
    self.tempBackgroundView.backgroundColor = kColor_W;
    [self addSubview:self.tempBackgroundView];
    [self addSubview:self.line];
    [self sendSubviewToBack:self.tempBackgroundView];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.tempBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
        self.tempBackgroundView.backgroundColor = kColor_W;
        [self addSubview:self.tempBackgroundView];
        [self addSubview:self.line];
        [self sendSubviewToBack:self.tempBackgroundView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.tempBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // 添加选中效果
    if (!self.tempBackgroundView) {
        self.tempBackgroundView = [[UIView alloc] initWithFrame:self.bounds];
        self.tempBackgroundView.backgroundColor = kColor_W;
        [self addSubview:self.tempBackgroundView];
        [self sendSubviewToBack:self.tempBackgroundView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    self.tempBackgroundView.frame = self.bounds;
    self.tempBackgroundView.backgroundColor = selected ? kColor_L3 : kColor_W;
    self.contentView.backgroundColor = UIColor.clearColor;
    [self.tempBackgroundView mas_remakeConstraints:^(MASConstraintMaker *make) {
       make.edges.mas_equalTo(0);
    }];
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    [super setHighlighted:highlighted animated:animated];
    self.tempBackgroundView.frame = self.bounds;
    self.tempBackgroundView.backgroundColor = highlighted ? kColor_L3 : kColor_W;
    [self.tempBackgroundView mas_remakeConstraints:^(MASConstraintMaker *make) {
       make.edges.mas_equalTo(0);
    }];
}
- (UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 43.5, kScreenWidth, 0.5)];
        _line.hidden = YES;
        _line.backgroundColor = kColor_L2;
    }
    return _line;
}

@end
